﻿namespace WMS6.SQLServerDAL
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.Common;
    using System.Data.SqlClient;
    using WMS6.Common;
    using WMS6.DataEntity;
    using WMS6.DBUtility;
    using WMS6.IDAL;
    using WMS6.QueryEntity;

    public class OwnerDA : IOwnerDA
    {
        private string ADDRESS = "@ADDRESS";
        private string ALLOW_AUTO_CLOSE_FOR_ASN = "@ALLOW_AUTO_CLOSE_FOR_ASN";
        private string ALLOW_AUTO_CLOSE_FOR_PO = "@ALLOW_AUTO_CLOSE_FOR_PO";
        private string ALLOW_COMMINGLED_LPN = "@ALLOW_COMMINGLED_LPN";
        private string ALLOW_OVER_SHIPMENT = "@ALLOW_OVER_SHIPMENT";
        private string ALLOW_SINGLE_SCANRECEIVING = "@ALLOW_SINGLE_SCANRECEIVING";
        private string ALLOW_SYSTEM_GENERATED_LPN = "@ALLOW_SYSTEM_GENERATED_LPN";
        private string APPLICATION_ID = "@APPLICATION_ID";
        private string APPORTION_RULE = "@APPORTION_RULE";
        private string ASN_ALPHA_PREFIX = "@ASN_ALPHA_PREFIX";
        private string ASN_REFER01 = "@ASN_REFER01";
        private string ASN_REFER02 = "@ASN_REFER02";
        private string ASN_REFER03 = "@ASN_REFER03";
        private string ASN_REFER04 = "@ASN_REFER04";
        private string ASN_REFER05 = "@ASN_REFER05";
        private string ASN_TO_LOT_ATTR01 = "@ASN_TO_LOT_ATTR01";
        private string ASN_TO_LOT_ATTR02 = "@ASN_TO_LOT_ATTR02";
        private string ASN_TO_LOT_ATTR03 = "@ASN_TO_LOT_ATTR03";
        private string ASN_TO_LOT_ATTR04 = "@ASN_TO_LOT_ATTR04";
        private string ASN_TO_LOT_ATTR05 = "@ASN_TO_LOT_ATTR05";
        private string B_ADDRESS = "@B_ADDRESS";
        private string B_CITY = "@B_CITY";
        private string B_CONTACT1 = "@B_CONTACT1";
        private string B_CONTACT2 = "@B_CONTACT2";
        private string B_COUNTRY = "@B_COUNTRY";
        private string B_COUNTRY_CODE = "@B_COUNTRY_CODE";
        private string B_EMAIL1 = "@B_EMAIL1";
        private string B_EMAIL2 = "@B_EMAIL2";
        private string B_FAX1 = "@B_FAX1";
        private string B_FAX2 = "@B_FAX2";
        private string B_PHONE1 = "@B_PHONE1";
        private string B_PHONE2 = "@B_PHONE2";
        private string B_STATE = "@B_STATE";
        private string B_ZIP = "@B_ZIP";
        private string BARCODE_CONFIG_ID = "@BARCODE_CONFIG_ID";
        private string CALCULATE_PUTAWAY_LOCATION = "@CALCULATE_PUTAWAY_LOCATION";
        private string CASE_LABEL_TYPE = "@CASE_LABEL_TYPE";
        private string CC_ADJ_BY_RF = "@CC_ADJ_BY_RF";
        private string CC_DISCREPANCY_RULE = "@CC_DISCREPANCY_RULE";
        private string CC_SKU_LOC = "@CC_SKU_LOC";
        private string CHECK_THE_WEIGHT_DIFFERENCE = "@CHECK_THE_WEIGHT_DIFFERENCE";
        private string CITY = "@CITY";
        private string COMPANY = "@COMPANY";
        private string CONTACT1 = "@CONTACT1";
        private string CONTACT2 = "@CONTACT2";
        private string COUNTRY = "@COUNTRY";
        private string COUNTRY_CODE = "@COUNTRY_CODE";
        private string CREATE_PA_TASK_ON_RF_RECEIPT = "@CREATE_PA_TASK_ON_RF_RECEIPT";
        private string CREATED_BY = "@CREATED_BY";
        private string CREDIT_LIMIT = "@CREDIT_LIMIT";
        private string DEFAULT_ALLOCATE_RULE_ID = "@DEFAULT_ALLOCATE_RULE_ID";
        private string DEFAULT_CARTON_GROUP = "@DEFAULT_CARTON_GROUP";
        private string DEFAULT_LOT_TEMPLATE_ID = "@DEFAULT_LOT_TEMPLATE_ID";
        private string DEFAULT_PACK_ID = "@DEFAULT_PACK_ID";
        private string DEFAULT_PACKING_LOCATION = "@DEFAULT_PACKING_LOCATION";
        private string DEFAULT_PREALLOCATE_RULE_ID = "@DEFAULT_PREALLOCATE_RULE_ID";
        private string DEFAULT_PUTAWAY_RULE_ID = "@DEFAULT_PUTAWAY_RULE_ID";
        private string DEFAULT_QC_LOC = "@DEFAULT_QC_LOC";
        private string DEFAULT_QC_LOC_OUT = "@DEFAULT_QC_LOC_OUT";
        private string DEFAULT_RETURNS_LOC = "@DEFAULT_RETURNS_LOC";
        private string DEFAULT_ROTATION_RULE_ID = "@DEFAULT_ROTATION_RULE_ID";
        private string DESCRIPTION = "@DESCRIPTION";
        private string DIFFERENCES_IN_APPROACH = "@DIFFERENCES_IN_APPROACH";
        private string DUP_CASE_ID = "@DUP_CASE_ID";
        private string EMAIL1 = "@EMAIL1";
        private string EMAIL2 = "@EMAIL2";
        private string ENABLE_OPP_XDOCK = "@ENABLE_OPP_XDOCK";
        private string ENABLE_PACKING_DEFAULT = "@ENABLE_PACKING_DEFAULT";
        private string FAX1 = "@FAX1";
        private string FAX2 = "@FAX2";
        private string FINANCE_LOGISTICAL_CALC_BY = "@FINANCE_LOGISTICAL_CALC_BY";
        private string FINANCE_LOGISTICAL_CTRL = "@FINANCE_LOGISTICAL_CTRL";
        private string INSPECT_AT_PACK = "@INSPECT_AT_PACK";
        private string IS_ACTIVE = "@IS_ACTIVE";
        private string IS_ASNREFER_TO_LOT01 = "@IS_ASNREFER_TO_LOT01";
        private string IS_ASNREFER_TO_LOT02 = "@IS_ASNREFER_TO_LOT02";
        private string IS_ASNREFER_TO_LOT03 = "@IS_ASNREFER_TO_LOT03";
        private string IS_ASNREFER_TO_LOT04 = "@IS_ASNREFER_TO_LOT04";
        private string IS_ASNREFER_TO_LOT05 = "@IS_ASNREFER_TO_LOT05";
        private string IS_REQUIRED_EXTERNAL_ID = "@IS_REQUIRED_EXTERNAL_ID";
        private string LPN_BARCODE_FORMAT = "@LPN_BARCODE_FORMAT";
        private string LPN_BARCODE_SYMBOLOGY = "@LPN_BARCODE_SYMBOLOGY";
        private string LPN_LENGTH = "@LPN_LENGTH";
        private string LPN_ROLLBACK_NUMBER = "@LPN_ROLLBACK_NUMBER";
        private string LPN_START_NUMBER = "@LPN_START_NUMBER";
        private string MAXIMUM_ORDERS = "@MAXIMUM_ORDERS";
        private string MINIMUM_PERCENT = "@MINIMUM_PERCENT";
        private string MULTI_ZONE_PL_PA = "@MULTI_ZONE_PL_PA";
        private string NEXT_LPN_NUMBER = "@NEXT_LPN_NUMBER";
        private string OPP_ORDER_STRATEGY_ID = "@OPP_ORDER_STRATEGY_ID";
        private string ORDER_BREAK_DEFAULT = "@ORDER_BREAK_DEFAULT";
        private string ORDER_DATE_END_DAYS = "@ORDER_DATE_END_DAYS";
        private string ORDER_DATE_START_DAYS = "@ORDER_DATE_START_DAYS";
        private string ORDER_TYPE_RESTRICT01 = "@ORDER_TYPE_RESTRICT01";
        private string ORDER_TYPE_RESTRICT02 = "@ORDER_TYPE_RESTRICT02";
        private string ORDER_TYPE_RESTRICT03 = "@ORDER_TYPE_RESTRICT03";
        private string ORDER_TYPE_RESTRICT04 = "@ORDER_TYPE_RESTRICT04";
        private string ORDER_TYPE_RESTRICT05 = "@ORDER_TYPE_RESTRICT05";
        private string ORDER_TYPE_RESTRICT06 = "@ORDER_TYPE_RESTRICT06";
        private string OWNER_ID = "@OWNER_ID";
        private string PACKING_VALIDATION_TEMPLATE = "@PACKING_VALIDATION_TEMPLATE";
        private string PERCENTAGE_WEIGHT_DIFFERENCE = "@PERCENTAGE_WEIGHT_DIFFERENCE";
        private string PHONE1 = "@PHONE1";
        private string PHONE2 = "@PHONE2";
        private string PI_SKU_LOC = "@PI_SKU_LOC";
        private string PO_ALPHA_PREFIX = "@PO_ALPHA_PREFIX";
        private string RECEIPT_VALIDATION_ID = "@RECEIPT_VALIDATION_ID";
        private string REMARK = "@REMARK";
        private string SAME_WEIGHT_BY_STYLE = "@SAME_WEIGHT_BY_STYLE";
        private string SKU_SETUP_REQUIRED = "@SKU_SETUP_REQUIRED";
        private string SO_ALPHA_PREFIX = "@SO_ALPHA_PREFIX";
        private string SQL_CHECK_OWNER_ID_UNIQUE = " SELECT COUNT(1) FROM @_@OWNER WHERE OWNER_ID = @OWNER_ID ";
        private string SQL_CHECK_SAME_WEIGHT_BY_STYLE = " SELECT SAME_WEIGHT_BY_STYLE FROM @_@OWNER WHERE OWNER_ID = @OWNER_ID ";
        private string SQL_DELETE_OWNER = " DELETE FROM @_@OWNER WHERE OWNER_ID = @OWNER_ID ";
        private string SQL_INSERT_OWNER = " INSERT INTO @_@OWNER ( WH_ID, OWNER_ID, TYPE, COMPANY, DESCRIPTION, VAT, CREDIT_LIMIT, PO_ALPHA_PREFIX, ASN_ALPHA_PREFIX, SO_ALPHA_PREFIX, CITY, STATE, ZIP, COUNTRY, COUNTRY_CODE, ADDRESS, CONTACT1, CONTACT2, PHONE1, PHONE2, FAX1, FAX2, EMAIL1, EMAIL2, B_CITY, B_STATE, B_ZIP, B_COUNTRY, B_COUNTRY_CODE, B_ADDRESS, B_CONTACT1, B_CONTACT2, B_PHONE1, B_PHONE2, B_FAX1, B_FAX2, B_EMAIL1, B_EMAIL2, DEFAULT_CARTON_GROUP, DEFAULT_PACK_ID, DEFAULT_LOT_TEMPLATE_ID, DEFAULT_PUTAWAY_RULE_ID, DEFAULT_PREALLOCATE_RULE_ID, DEFAULT_ALLOCATE_RULE_ID, DEFAULT_ROTATION_RULE_ID, CALCULATE_PUTAWAY_LOCATION, RECEIPT_VALIDATION_ID, DEFAULT_QC_LOC, DEFAULT_QC_LOC_OUT, DEFAULT_RETURNS_LOC, DEFAULT_PACKING_LOCATION, UDF1, UDF2, UDF3, UDF4, UDF5, UDF6, UDF7, UDF8, UDF9, UDF10, REMARK, PACKING_VALIDATION_TEMPLATE, ENABLE_OPP_XDOCK, OPP_ORDER_STRATEGY_ID, ALLOW_OVER_SHIPMENT, APPORTION_RULE, ORDER_DATE_START_DAYS, ORDER_DATE_END_DAYS, MAXIMUM_ORDERS, MINIMUM_PERCENT, ORDER_TYPE_RESTRICT01, ORDER_TYPE_RESTRICT02, ORDER_TYPE_RESTRICT03, ORDER_TYPE_RESTRICT04, ORDER_TYPE_RESTRICT05, ORDER_TYPE_RESTRICT06, ENABLE_PACKING_DEFAULT, INSPECT_AT_PACK, MULTI_ZONE_PL_PA, CREATE_PA_TASK_ON_RF_RECEIPT, ORDER_BREAK_DEFAULT, LPN_BARCODE_SYMBOLOGY, LPN_BARCODE_FORMAT, LPN_LENGTH, LPN_START_NUMBER, NEXT_LPN_NUMBER, LPN_ROLLBACK_NUMBER, CASE_LABEL_TYPE, APPLICATION_ID, SSCC_1ST_DIGIT, UCC_VENDOR_NUMBER, CC_DISCREPANCY_RULE, CC_ADJ_BY_RF, CC_SKU_LOC, PI_SKU_LOC, ALLOW_COMMINGLED_LPN, ALLOW_AUTO_CLOSE_FOR_ASN, ALLOW_AUTO_CLOSE_FOR_PO, ALLOW_SYSTEM_GENERATED_LPN, ALLOW_SINGLE_SCANRECEIVING, BARCODE_CONFIG_ID, TRACK_INVENTORY_BY, DUP_CASE_ID, SKU_SETUP_REQUIRED, IS_ACTIVE, CREATED_BY, CREATED_DATE, UPDATED_BY, UPDATED_DATE, IS_REQUIRED_EXTERNAL_ID, FINANCE_LOGISTICAL_CTRL, FINANCE_LOGISTICAL_CALC_BY, CHECK_THE_WEIGHT_DIFFERENCE, PERCENTAGE_WEIGHT_DIFFERENCE, DIFFERENCES_IN_APPROACH, SAME_WEIGHT_BY_STYLE, IS_ASNREFER_TO_LOT01, ASN_REFER01, ASN_TO_LOT_ATTR01, IS_ASNREFER_TO_LOT02, ASN_REFER02, ASN_TO_LOT_ATTR02, IS_ASNREFER_TO_LOT03, ASN_REFER03, ASN_TO_LOT_ATTR03, IS_ASNREFER_TO_LOT04, ASN_REFER04, ASN_TO_LOT_ATTR04, IS_ASNREFER_TO_LOT05, ASN_REFER05, ASN_TO_LOT_ATTR05) VALUES ( @WH_ID, @OWNER_ID, @TYPE, @COMPANY, @DESCRIPTION, @VAT, @CREDIT_LIMIT, @PO_ALPHA_PREFIX, @ASN_ALPHA_PREFIX, @SO_ALPHA_PREFIX, @CITY, @STATE, @ZIP, @COUNTRY, @COUNTRY_CODE, @ADDRESS, @CONTACT1, @CONTACT2, @PHONE1, @PHONE2, @FAX1, @FAX2, @EMAIL1, @EMAIL2, @B_CITY, @B_STATE, @B_ZIP, @B_COUNTRY, @B_COUNTRY_CODE, @B_ADDRESS, @B_CONTACT1, @B_CONTACT2, @B_PHONE1, @B_PHONE2, @B_FAX1, @B_FAX2, @B_EMAIL1, @B_EMAIL2, @DEFAULT_CARTON_GROUP, @DEFAULT_PACK_ID, @DEFAULT_LOT_TEMPLATE_ID, @DEFAULT_PUTAWAY_RULE_ID, @DEFAULT_PREALLOCATE_RULE_ID, @DEFAULT_ALLOCATE_RULE_ID, @DEFAULT_ROTATION_RULE_ID, @CALCULATE_PUTAWAY_LOCATION, @RECEIPT_VALIDATION_ID, @DEFAULT_QC_LOC, @DEFAULT_QC_LOC_OUT, @DEFAULT_RETURNS_LOC, @DEFAULT_PACKING_LOCATION, @UDF1, @UDF2, @UDF3, @UDF4, @UDF5, @UDF6, @UDF7, @UDF8, @UDF9, @UDF10, @REMARK, @PACKING_VALIDATION_TEMPLATE, @ENABLE_OPP_XDOCK, @OPP_ORDER_STRATEGY_ID, @ALLOW_OVER_SHIPMENT, @APPORTION_RULE, @ORDER_DATE_START_DAYS, @ORDER_DATE_END_DAYS, @MAXIMUM_ORDERS, @MINIMUM_PERCENT, @ORDER_TYPE_RESTRICT01, @ORDER_TYPE_RESTRICT02, @ORDER_TYPE_RESTRICT03, @ORDER_TYPE_RESTRICT04, @ORDER_TYPE_RESTRICT05, @ORDER_TYPE_RESTRICT06, @ENABLE_PACKING_DEFAULT, @INSPECT_AT_PACK, @MULTI_ZONE_PL_PA, @CREATE_PA_TASK_ON_RF_RECEIPT, @ORDER_BREAK_DEFAULT, @LPN_BARCODE_SYMBOLOGY, @LPN_BARCODE_FORMAT, @LPN_LENGTH, @LPN_START_NUMBER, @NEXT_LPN_NUMBER, @LPN_ROLLBACK_NUMBER, @CASE_LABEL_TYPE, @APPLICATION_ID, @SSCC_1ST_DIGIT, @UCC_VENDOR_NUMBER, @CC_DISCREPANCY_RULE, @CC_ADJ_BY_RF, @CC_SKU_LOC, @PI_SKU_LOC, @ALLOW_COMMINGLED_LPN, @ALLOW_AUTO_CLOSE_FOR_ASN, @ALLOW_AUTO_CLOSE_FOR_PO, @ALLOW_SYSTEM_GENERATED_LPN, @ALLOW_SINGLE_SCANRECEIVING, @BARCODE_CONFIG_ID, @TRACK_INVENTORY_BY, @DUP_CASE_ID, @SKU_SETUP_REQUIRED, @IS_ACTIVE, @CREATED_BY, GETDATE(), @UPDATED_BY, GETDATE(), @IS_REQUIRED_EXTERNAL_ID, @FINANCE_LOGISTICAL_CTRL, @FINANCE_LOGISTICAL_CALC_BY, @CHECK_THE_WEIGHT_DIFFERENCE, @PERCENTAGE_WEIGHT_DIFFERENCE, @DIFFERENCES_IN_APPROACH, @SAME_WEIGHT_BY_STYLE, @IS_ASNREFER_TO_LOT01, @ASN_REFER01, @ASN_TO_LOT_ATTR01, @IS_ASNREFER_TO_LOT02, @ASN_REFER02, @ASN_TO_LOT_ATTR02, @IS_ASNREFER_TO_LOT03, @ASN_REFER03, @ASN_TO_LOT_ATTR03, @IS_ASNREFER_TO_LOT04, @ASN_REFER04, @ASN_TO_LOT_ATTR04, @IS_ASNREFER_TO_LOT05, @ASN_REFER05, @ASN_TO_LOT_ATTR05)  ";
        private string SQL_SELECT_ALL_OWNER = " SELECT  ROWID, WH_ID, OWNER_ID, TYPE, COMPANY, DESCRIPTION, VAT, CREDIT_LIMIT, PO_ALPHA_PREFIX, ASN_ALPHA_PREFIX, SO_ALPHA_PREFIX, CITY, STATE, ZIP, COUNTRY, COUNTRY_CODE, ADDRESS, CONTACT1, CONTACT2, PHONE1, PHONE2, FAX1, FAX2, EMAIL1, EMAIL2, B_CITY, B_STATE, B_ZIP, B_COUNTRY, B_COUNTRY_CODE, B_ADDRESS, B_CONTACT1, B_CONTACT2, B_PHONE1, B_PHONE2, B_FAX1, B_FAX2, B_EMAIL1, B_EMAIL2, DEFAULT_CARTON_GROUP, DEFAULT_PACK_ID, DEFAULT_LOT_TEMPLATE_ID, DEFAULT_PUTAWAY_RULE_ID, DEFAULT_PREALLOCATE_RULE_ID, DEFAULT_ALLOCATE_RULE_ID, DEFAULT_ROTATION_RULE_ID, CALCULATE_PUTAWAY_LOCATION, RECEIPT_VALIDATION_ID, DEFAULT_QC_LOC, DEFAULT_QC_LOC_OUT, DEFAULT_RETURNS_LOC, DEFAULT_PACKING_LOCATION, UDF1, UDF2, UDF3, UDF4, UDF5, UDF6, UDF7, UDF8, UDF9, UDF10, REMARK, PACKING_VALIDATION_TEMPLATE, ENABLE_OPP_XDOCK, OPP_ORDER_STRATEGY_ID, ALLOW_OVER_SHIPMENT, APPORTION_RULE, ORDER_DATE_START_DAYS, ORDER_DATE_END_DAYS, MAXIMUM_ORDERS, MINIMUM_PERCENT, ORDER_TYPE_RESTRICT01, ORDER_TYPE_RESTRICT02, ORDER_TYPE_RESTRICT03, ORDER_TYPE_RESTRICT04, ORDER_TYPE_RESTRICT05, ORDER_TYPE_RESTRICT06, ENABLE_PACKING_DEFAULT, INSPECT_AT_PACK, MULTI_ZONE_PL_PA, CREATE_PA_TASK_ON_RF_RECEIPT, ORDER_BREAK_DEFAULT, LPN_BARCODE_SYMBOLOGY, LPN_BARCODE_FORMAT, LPN_LENGTH, LPN_START_NUMBER, NEXT_LPN_NUMBER, LPN_ROLLBACK_NUMBER, CASE_LABEL_TYPE, APPLICATION_ID, SSCC_1ST_DIGIT, UCC_VENDOR_NUMBER, CC_DISCREPANCY_RULE, CC_ADJ_BY_RF, CC_SKU_LOC, PI_SKU_LOC, ALLOW_COMMINGLED_LPN, ALLOW_AUTO_CLOSE_FOR_ASN, ALLOW_AUTO_CLOSE_FOR_PO, ALLOW_SYSTEM_GENERATED_LPN, ALLOW_SINGLE_SCANRECEIVING, BARCODE_CONFIG_ID, TRACK_INVENTORY_BY, DUP_CASE_ID, SKU_SETUP_REQUIRED, IS_ACTIVE, TS, CREATED_BY, CREATED_DATE, UPDATED_BY, UPDATED_DATE, IS_REQUIRED_EXTERNAL_ID, FINANCE_LOGISTICAL_CTRL, FINANCE_LOGISTICAL_CALC_BY, CHECK_THE_WEIGHT_DIFFERENCE, PERCENTAGE_WEIGHT_DIFFERENCE, DIFFERENCES_IN_APPROACH, SAME_WEIGHT_BY_STYLE, IS_ASNREFER_TO_LOT01, ASN_REFER01, ASN_TO_LOT_ATTR01, IS_ASNREFER_TO_LOT02, ASN_REFER02, ASN_TO_LOT_ATTR02, IS_ASNREFER_TO_LOT03, ASN_REFER03, ASN_TO_LOT_ATTR03, IS_ASNREFER_TO_LOT04, ASN_REFER04, ASN_TO_LOT_ATTR04, IS_ASNREFER_TO_LOT05, ASN_REFER05, ASN_TO_LOT_ATTR05  FROM  @_@OWNER ";
        private string SQL_UPDATE_OWNER = " UPDATE @_@OWNER SET WH_ID = @WH_ID, TYPE = @TYPE, COMPANY = @COMPANY, DESCRIPTION = @DESCRIPTION, VAT = @VAT, CREDIT_LIMIT = @CREDIT_LIMIT, PO_ALPHA_PREFIX = @PO_ALPHA_PREFIX, ASN_ALPHA_PREFIX = @ASN_ALPHA_PREFIX, SO_ALPHA_PREFIX = @SO_ALPHA_PREFIX, CITY = @CITY, STATE = @STATE, ZIP = @ZIP, COUNTRY = @COUNTRY, COUNTRY_CODE = @COUNTRY_CODE, ADDRESS = @ADDRESS, CONTACT1 = @CONTACT1, CONTACT2 = @CONTACT2, PHONE1 = @PHONE1, PHONE2 = @PHONE2, FAX1 = @FAX1, FAX2 = @FAX2, EMAIL1 = @EMAIL1, EMAIL2 = @EMAIL2, B_CITY = @B_CITY, B_STATE = @B_STATE, B_ZIP = @B_ZIP, B_COUNTRY = @B_COUNTRY, B_COUNTRY_CODE = @B_COUNTRY_CODE, B_ADDRESS = @B_ADDRESS, B_CONTACT1 = @B_CONTACT1, B_CONTACT2 = @B_CONTACT2, B_PHONE1 = @B_PHONE1, B_PHONE2 = @B_PHONE2, B_FAX1 = @B_FAX1, B_FAX2 = @B_FAX2, B_EMAIL1 = @B_EMAIL1, B_EMAIL2 = @B_EMAIL2, DEFAULT_CARTON_GROUP = @DEFAULT_CARTON_GROUP, DEFAULT_PACK_ID = @DEFAULT_PACK_ID, DEFAULT_LOT_TEMPLATE_ID = @DEFAULT_LOT_TEMPLATE_ID, DEFAULT_PUTAWAY_RULE_ID = @DEFAULT_PUTAWAY_RULE_ID, DEFAULT_PREALLOCATE_RULE_ID = @DEFAULT_PREALLOCATE_RULE_ID, DEFAULT_ALLOCATE_RULE_ID = @DEFAULT_ALLOCATE_RULE_ID, DEFAULT_ROTATION_RULE_ID = @DEFAULT_ROTATION_RULE_ID, CALCULATE_PUTAWAY_LOCATION = @CALCULATE_PUTAWAY_LOCATION, RECEIPT_VALIDATION_ID = @RECEIPT_VALIDATION_ID, DEFAULT_QC_LOC = @DEFAULT_QC_LOC, DEFAULT_QC_LOC_OUT = @DEFAULT_QC_LOC_OUT, DEFAULT_RETURNS_LOC = @DEFAULT_RETURNS_LOC, DEFAULT_PACKING_LOCATION = @DEFAULT_PACKING_LOCATION, UDF1 = @UDF1, UDF2 = @UDF2, UDF3 = @UDF3, UDF4 = @UDF4, UDF5 = @UDF5, UDF6 = @UDF6, UDF7 = @UDF7, UDF8 = @UDF8, UDF9 = @UDF9, UDF10 = @UDF10, REMARK = @REMARK, PACKING_VALIDATION_TEMPLATE = @PACKING_VALIDATION_TEMPLATE, ENABLE_OPP_XDOCK = @ENABLE_OPP_XDOCK, OPP_ORDER_STRATEGY_ID = @OPP_ORDER_STRATEGY_ID, ALLOW_OVER_SHIPMENT = @ALLOW_OVER_SHIPMENT, APPORTION_RULE = @APPORTION_RULE, ORDER_DATE_START_DAYS = @ORDER_DATE_START_DAYS, ORDER_DATE_END_DAYS = @ORDER_DATE_END_DAYS, MAXIMUM_ORDERS = @MAXIMUM_ORDERS, MINIMUM_PERCENT = @MINIMUM_PERCENT, ORDER_TYPE_RESTRICT01 = @ORDER_TYPE_RESTRICT01, ORDER_TYPE_RESTRICT02 = @ORDER_TYPE_RESTRICT02, ORDER_TYPE_RESTRICT03 = @ORDER_TYPE_RESTRICT03, ORDER_TYPE_RESTRICT04 = @ORDER_TYPE_RESTRICT04, ORDER_TYPE_RESTRICT05 = @ORDER_TYPE_RESTRICT05, ORDER_TYPE_RESTRICT06 = @ORDER_TYPE_RESTRICT06, ENABLE_PACKING_DEFAULT = @ENABLE_PACKING_DEFAULT, INSPECT_AT_PACK = @INSPECT_AT_PACK, MULTI_ZONE_PL_PA = @MULTI_ZONE_PL_PA, CREATE_PA_TASK_ON_RF_RECEIPT = @CREATE_PA_TASK_ON_RF_RECEIPT, ORDER_BREAK_DEFAULT = @ORDER_BREAK_DEFAULT, LPN_BARCODE_SYMBOLOGY = @LPN_BARCODE_SYMBOLOGY, LPN_BARCODE_FORMAT = @LPN_BARCODE_FORMAT, LPN_LENGTH = @LPN_LENGTH, LPN_START_NUMBER = @LPN_START_NUMBER, NEXT_LPN_NUMBER = @NEXT_LPN_NUMBER, LPN_ROLLBACK_NUMBER = @LPN_ROLLBACK_NUMBER, CASE_LABEL_TYPE = @CASE_LABEL_TYPE, APPLICATION_ID = @APPLICATION_ID, SSCC_1ST_DIGIT = @SSCC_1ST_DIGIT, UCC_VENDOR_NUMBER = @UCC_VENDOR_NUMBER, CC_DISCREPANCY_RULE = @CC_DISCREPANCY_RULE, CC_ADJ_BY_RF = @CC_ADJ_BY_RF, CC_SKU_LOC = @CC_SKU_LOC, PI_SKU_LOC = @PI_SKU_LOC, ALLOW_COMMINGLED_LPN = @ALLOW_COMMINGLED_LPN, ALLOW_AUTO_CLOSE_FOR_ASN = @ALLOW_AUTO_CLOSE_FOR_ASN, ALLOW_AUTO_CLOSE_FOR_PO = @ALLOW_AUTO_CLOSE_FOR_PO, ALLOW_SYSTEM_GENERATED_LPN = @ALLOW_SYSTEM_GENERATED_LPN, ALLOW_SINGLE_SCANRECEIVING = @ALLOW_SINGLE_SCANRECEIVING, BARCODE_CONFIG_ID = @BARCODE_CONFIG_ID, TRACK_INVENTORY_BY = @TRACK_INVENTORY_BY, DUP_CASE_ID = @DUP_CASE_ID, SKU_SETUP_REQUIRED = @SKU_SETUP_REQUIRED, IS_ACTIVE = @IS_ACTIVE, UPDATED_BY = @UPDATED_BY, UPDATED_DATE = GETDATE(), IS_REQUIRED_EXTERNAL_ID = @IS_REQUIRED_EXTERNAL_ID, FINANCE_LOGISTICAL_CTRL = @FINANCE_LOGISTICAL_CTRL, FINANCE_LOGISTICAL_CALC_BY = @FINANCE_LOGISTICAL_CALC_BY, CHECK_THE_WEIGHT_DIFFERENCE = @CHECK_THE_WEIGHT_DIFFERENCE, PERCENTAGE_WEIGHT_DIFFERENCE = @PERCENTAGE_WEIGHT_DIFFERENCE, DIFFERENCES_IN_APPROACH = @DIFFERENCES_IN_APPROACH, SAME_WEIGHT_BY_STYLE = @SAME_WEIGHT_BY_STYLE, IS_ASNREFER_TO_LOT01 = @IS_ASNREFER_TO_LOT01, ASN_REFER01 = @ASN_REFER01, ASN_TO_LOT_ATTR01 = @ASN_TO_LOT_ATTR01, IS_ASNREFER_TO_LOT02 = @IS_ASNREFER_TO_LOT02, ASN_REFER02 = @ASN_REFER02, ASN_TO_LOT_ATTR02 = @ASN_TO_LOT_ATTR02, IS_ASNREFER_TO_LOT03 = @IS_ASNREFER_TO_LOT03, ASN_REFER03 = @ASN_REFER03, ASN_TO_LOT_ATTR03 = @ASN_TO_LOT_ATTR03, IS_ASNREFER_TO_LOT04 = @IS_ASNREFER_TO_LOT04, ASN_REFER04 = @ASN_REFER04, ASN_TO_LOT_ATTR04 = @ASN_TO_LOT_ATTR04, IS_ASNREFER_TO_LOT05 = @IS_ASNREFER_TO_LOT05, ASN_REFER05 = @ASN_REFER05, ASN_TO_LOT_ATTR05 = @ASN_TO_LOT_ATTR05 WHERE OWNER_ID = @OWNER_ID  ";
        private string SSCC_1ST_DIGIT = "@SSCC_1ST_DIGIT";
        private string STATE = "@STATE";
        private string TRACK_INVENTORY_BY = "@TRACK_INVENTORY_BY";
        private string TS = "@TS";
        private string TYPE = "@TYPE";
        private string UCC_VENDOR_NUMBER = "@UCC_VENDOR_NUMBER";
        private string UDF1 = "@UDF1";
        private string UDF10 = "@UDF10";
        private string UDF2 = "@UDF2";
        private string UDF3 = "@UDF3";
        private string UDF4 = "@UDF4";
        private string UDF5 = "@UDF5";
        private string UDF6 = "@UDF6";
        private string UDF7 = "@UDF7";
        private string UDF8 = "@UDF8";
        private string UDF9 = "@UDF9";
        private string UPDATED_BY = "@UPDATED_BY";
        private string VAT = "@VAT";
        private string WH_ID = "@WH_ID";
        private string ZIP = "@ZIP";

        public bool CheckSameWeightByStyle(string ownerID, string whLoginID)
        {
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@OWNER_ID", ownerID) };
            return (DBHelper.ExecuteScalar(CommandType.Text, this.SQL_CHECK_SAME_WEIGHT_BY_STYLE.Replace("@_@", whLoginID), paras).ToString() == "Y");
        }

        public bool CheckSameWeightByStyle(DataBase dataBase, DbTransaction tran, string ownerID, string whLoginID)
        {
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@OWNER_ID", ownerID) };
            return (dataBase.ExecuteScalar(tran, CommandType.Text, this.SQL_CHECK_SAME_WEIGHT_BY_STYLE.Replace("@_@", whLoginID), paras).ToString() == "Y");
        }

        public bool CheckTradePartnerIDUnique(string tradePartnerID, string whLoginID)
        {
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@OWNER_ID", tradePartnerID) };
            return (DBHelper.ExecuteScalar(CommandType.Text, this.SQL_CHECK_OWNER_ID_UNIQUE.Replace("@_@", whLoginID), paras).ToString() == "1");
        }

        public bool CheckTradePartnerIDUnique(DataBase dataBase, DbTransaction tran, string tradePartnerID, string whLoginID)
        {
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@OWNER_ID", tradePartnerID) };
            return (dataBase.ExecuteScalar(tran, CommandType.Text, this.SQL_CHECK_OWNER_ID_UNIQUE.Replace("@_@", whLoginID), paras).ToString() == "1");
        }

        public int DeleteTradePartner(List<string> tradePartnerID, List<string> whLoginID)
        {
            int result = 0;
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    for (int j = 0; j < tradePartnerID.Count; j++)
                    {
                        SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@OWNER_ID", tradePartnerID[j]) };
                        result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_DELETE_OWNER.Replace("@_@", whLoginID[i]), paras);
                    }
                }
                tran.Commit();
            }
            catch (SqlException sqlEx)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return result;
        }

        public int DeleteTradePartner(DataBase dataBase, DbTransaction tran, List<string> tradePartnerID, List<string> whLoginID)
        {
            int result = 0;
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    for (int j = 0; j < tradePartnerID.Count; j++)
                    {
                        SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@OWNER_ID", tradePartnerID[j]) };
                        result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_DELETE_OWNER.Replace("@_@", whLoginID[i]), paras);
                    }
                }
            }
            catch (SqlException sqlEx)
            {
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }

        public DataSet GetAllTradePartner(string whLoginID)
        {
            string sql = this.SQL_SELECT_ALL_OWNER.Replace("@_@", whLoginID);
            return DBHelper.ExecuteDataSet(CommandType.Text, sql);
        }

        public DataSet GetAllTradePartner(DataBase dataBase, DbTransaction tran, string whLoginID)
        {
            string sql = this.SQL_SELECT_ALL_OWNER.Replace("@_@", whLoginID);
            return dataBase.ExecuteDataSet(tran, CommandType.Text, sql);
        }

        public TradePartnerInfo GetTradePartnerByID(string tradePartnerID, string whLoginID)
        {
            string sql = this.SQL_SELECT_ALL_OWNER.Replace("@_@", whLoginID) + " WHERE OWNER_ID = @OWNER_ID  ";
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@OWNER_ID", tradePartnerID) };
            TradePartnerInfo tradePartnerInfo = null;
            using (IDataReader reader = DBHelper.ExecuteReader(CommandType.Text, sql, paras))
            {
                if (reader.Read())
                {
                    tradePartnerInfo = new TradePartnerInfo((reader["ROWID"].ToString() != "") ? int.Parse(reader["ROWID"].ToString()) : 0, reader["WH_ID"].ToString(), reader["OWNER_ID"].ToString(), reader["TYPE"].ToString(), reader["COMPANY"].ToString(), reader["DESCRIPTION"].ToString(), reader["VAT"].ToString(), reader["CREDIT_LIMIT"].ToString(), reader["PO_ALPHA_PREFIX"].ToString(), reader["ASN_ALPHA_PREFIX"].ToString(), reader["SO_ALPHA_PREFIX"].ToString(), reader["CITY"].ToString(), reader["STATE"].ToString(), reader["ZIP"].ToString(), reader["COUNTRY"].ToString(), reader["COUNTRY_CODE"].ToString(), reader["ADDRESS"].ToString(), reader["CONTACT1"].ToString(), reader["CONTACT2"].ToString(), reader["PHONE1"].ToString(), reader["PHONE2"].ToString(), reader["FAX1"].ToString(), reader["FAX2"].ToString(), reader["EMAIL1"].ToString(), reader["EMAIL2"].ToString(), reader["B_CITY"].ToString(), reader["B_STATE"].ToString(), reader["B_ZIP"].ToString(), reader["B_COUNTRY"].ToString(), reader["B_COUNTRY_CODE"].ToString(), reader["B_ADDRESS"].ToString(), reader["B_CONTACT1"].ToString(), reader["B_CONTACT2"].ToString(), reader["B_PHONE1"].ToString(), reader["B_PHONE2"].ToString(), reader["B_FAX1"].ToString(), reader["B_FAX2"].ToString(), reader["B_EMAIL1"].ToString(), reader["B_EMAIL2"].ToString(), reader["DEFAULT_CARTON_GROUP"].ToString(), reader["DEFAULT_PACK_ID"].ToString(), reader["DEFAULT_LOT_TEMPLATE_ID"].ToString(), reader["DEFAULT_PUTAWAY_RULE_ID"].ToString(), reader["DEFAULT_PREALLOCATE_RULE_ID"].ToString(), reader["DEFAULT_ALLOCATE_RULE_ID"].ToString(), reader["DEFAULT_ROTATION_RULE_ID"].ToString(), reader["CALCULATE_PUTAWAY_LOCATION"].ToString(), reader["RECEIPT_VALIDATION_ID"].ToString(), reader["DEFAULT_QC_LOC"].ToString(), reader["DEFAULT_QC_LOC_OUT"].ToString(), reader["DEFAULT_RETURNS_LOC"].ToString(), reader["DEFAULT_PACKING_LOCATION"].ToString(), reader["UDF1"].ToString(), reader["UDF2"].ToString(), reader["UDF3"].ToString(), reader["UDF4"].ToString(), reader["UDF5"].ToString(), reader["UDF6"].ToString(), reader["UDF7"].ToString(), reader["UDF8"].ToString(), reader["UDF9"].ToString(), reader["UDF10"].ToString(), reader["REMARK"].ToString(), reader["PACKING_VALIDATION_TEMPLATE"].ToString(), reader["ENABLE_OPP_XDOCK"].ToString(), reader["OPP_ORDER_STRATEGY_ID"].ToString(), reader["ALLOW_OVER_SHIPMENT"].ToString(), reader["APPORTION_RULE"].ToString(), (reader["ORDER_DATE_START_DAYS"].ToString() != "") ? int.Parse(reader["ORDER_DATE_START_DAYS"].ToString()) : 0, (reader["ORDER_DATE_END_DAYS"].ToString() != "") ? int.Parse(reader["ORDER_DATE_END_DAYS"].ToString()) : 0, (reader["MAXIMUM_ORDERS"].ToString() != "") ? int.Parse(reader["MAXIMUM_ORDERS"].ToString()) : 0, (reader["MINIMUM_PERCENT"].ToString() != "") ? decimal.Parse(reader["MINIMUM_PERCENT"].ToString()) : 0M, reader["ORDER_TYPE_RESTRICT01"].ToString(), reader["ORDER_TYPE_RESTRICT02"].ToString(), reader["ORDER_TYPE_RESTRICT03"].ToString(), reader["ORDER_TYPE_RESTRICT04"].ToString(), reader["ORDER_TYPE_RESTRICT05"].ToString(), reader["ORDER_TYPE_RESTRICT06"].ToString(), reader["ENABLE_PACKING_DEFAULT"].ToString(), reader["INSPECT_AT_PACK"].ToString(), reader["MULTI_ZONE_PL_PA"].ToString(), reader["CREATE_PA_TASK_ON_RF_RECEIPT"].ToString(), reader["ORDER_BREAK_DEFAULT"].ToString(), reader["LPN_BARCODE_SYMBOLOGY"].ToString(), reader["LPN_BARCODE_FORMAT"].ToString(), (reader["LPN_LENGTH"].ToString() != "") ? int.Parse(reader["LPN_LENGTH"].ToString()) : 0, reader["LPN_START_NUMBER"].ToString(), reader["NEXT_LPN_NUMBER"].ToString(), reader["LPN_ROLLBACK_NUMBER"].ToString(), reader["CASE_LABEL_TYPE"].ToString(), reader["APPLICATION_ID"].ToString(), (reader["SSCC_1ST_DIGIT"].ToString() != "") ? int.Parse(reader["SSCC_1ST_DIGIT"].ToString()) : 0, reader["UCC_VENDOR_NUMBER"].ToString(), reader["CC_DISCREPANCY_RULE"].ToString(), reader["CC_ADJ_BY_RF"].ToString(), reader["CC_SKU_LOC"].ToString(), reader["PI_SKU_LOC"].ToString(), reader["ALLOW_COMMINGLED_LPN"].ToString(), reader["ALLOW_AUTO_CLOSE_FOR_ASN"].ToString(), reader["ALLOW_AUTO_CLOSE_FOR_PO"].ToString(), reader["ALLOW_SYSTEM_GENERATED_LPN"].ToString(), reader["ALLOW_SINGLE_SCANRECEIVING"].ToString(), reader["BARCODE_CONFIG_ID"].ToString(), reader["TRACK_INVENTORY_BY"].ToString(), reader["DUP_CASE_ID"].ToString(), reader["SKU_SETUP_REQUIRED"].ToString(), reader["IS_ACTIVE"].ToString(), (byte[]) reader["TS"], reader["CREATED_BY"].ToString(), (reader["CREATED_DATE"].ToString() != "") ? DateTime.Parse(reader["CREATED_DATE"].ToString()) : new DateTime(), reader["UPDATED_BY"].ToString(), (reader["UPDATED_DATE"].ToString() != "") ? DateTime.Parse(reader["UPDATED_DATE"].ToString()) : new DateTime(), reader["IS_REQUIRED_EXTERNAL_ID"].ToString(), reader["FINANCE_LOGISTICAL_CTRL"].ToString(), reader["FINANCE_LOGISTICAL_CALC_BY"].ToString(), reader["CHECK_THE_WEIGHT_DIFFERENCE"].ToString(), (reader["PERCENTAGE_WEIGHT_DIFFERENCE"].ToString() != "") ? Convert.ToDecimal(reader["PERCENTAGE_WEIGHT_DIFFERENCE"]) : 0M, reader["DIFFERENCES_IN_APPROACH"].ToString(), reader["SAME_WEIGHT_BY_STYLE"].ToString(), reader["IS_ASNREFER_TO_LOT01"].ToString(), reader["ASN_REFER01"].ToString(), reader["ASN_TO_LOT_ATTR01"].ToString(), reader["IS_ASNREFER_TO_LOT02"].ToString(), reader["ASN_REFER02"].ToString(), reader["ASN_TO_LOT_ATTR02"].ToString(), reader["IS_ASNREFER_TO_LOT03"].ToString(), reader["ASN_REFER03"].ToString(), reader["ASN_TO_LOT_ATTR03"].ToString(), reader["IS_ASNREFER_TO_LOT04"].ToString(), reader["ASN_REFER04"].ToString(), reader["ASN_TO_LOT_ATTR04"].ToString(), reader["IS_ASNREFER_TO_LOT05"].ToString(), reader["ASN_REFER05"].ToString(), reader["ASN_TO_LOT_ATTR05"].ToString());
                }
            }
            return tradePartnerInfo;
        }

        public TradePartnerInfo GetTradePartnerByID(DataBase dataBase, DbTransaction tran, string tradePartnerID, string whLoginID)
        {
            string sql = this.SQL_SELECT_ALL_OWNER.Replace("@_@", whLoginID) + " WHERE OWNER_ID = @OWNER_ID  ";
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@OWNER_ID", tradePartnerID) };
            TradePartnerInfo tradePartnerInfo = null;
            IDataReader reader = dataBase.ExecuteReader(tran, CommandType.Text, sql, paras);
            if (reader.Read())
            {
                tradePartnerInfo = new TradePartnerInfo((reader["ROWID"].ToString() != "") ? int.Parse(reader["ROWID"].ToString()) : 0, reader["WH_ID"].ToString(), reader["OWNER_ID"].ToString(), reader["TYPE"].ToString(), reader["COMPANY"].ToString(), reader["DESCRIPTION"].ToString(), reader["VAT"].ToString(), reader["CREDIT_LIMIT"].ToString(), reader["PO_ALPHA_PREFIX"].ToString(), reader["ASN_ALPHA_PREFIX"].ToString(), reader["SO_ALPHA_PREFIX"].ToString(), reader["CITY"].ToString(), reader["STATE"].ToString(), reader["ZIP"].ToString(), reader["COUNTRY"].ToString(), reader["COUNTRY_CODE"].ToString(), reader["ADDRESS"].ToString(), reader["CONTACT1"].ToString(), reader["CONTACT2"].ToString(), reader["PHONE1"].ToString(), reader["PHONE2"].ToString(), reader["FAX1"].ToString(), reader["FAX2"].ToString(), reader["EMAIL1"].ToString(), reader["EMAIL2"].ToString(), reader["B_CITY"].ToString(), reader["B_STATE"].ToString(), reader["B_ZIP"].ToString(), reader["B_COUNTRY"].ToString(), reader["B_COUNTRY_CODE"].ToString(), reader["B_ADDRESS"].ToString(), reader["B_CONTACT1"].ToString(), reader["B_CONTACT2"].ToString(), reader["B_PHONE1"].ToString(), reader["B_PHONE2"].ToString(), reader["B_FAX1"].ToString(), reader["B_FAX2"].ToString(), reader["B_EMAIL1"].ToString(), reader["B_EMAIL2"].ToString(), reader["DEFAULT_CARTON_GROUP"].ToString(), reader["DEFAULT_PACK_ID"].ToString(), reader["DEFAULT_LOT_TEMPLATE_ID"].ToString(), reader["DEFAULT_PUTAWAY_RULE_ID"].ToString(), reader["DEFAULT_PREALLOCATE_RULE_ID"].ToString(), reader["DEFAULT_ALLOCATE_RULE_ID"].ToString(), reader["DEFAULT_ROTATION_RULE_ID"].ToString(), reader["CALCULATE_PUTAWAY_LOCATION"].ToString(), reader["RECEIPT_VALIDATION_ID"].ToString(), reader["DEFAULT_QC_LOC"].ToString(), reader["DEFAULT_QC_LOC_OUT"].ToString(), reader["DEFAULT_RETURNS_LOC"].ToString(), reader["DEFAULT_PACKING_LOCATION"].ToString(), reader["UDF1"].ToString(), reader["UDF2"].ToString(), reader["UDF3"].ToString(), reader["UDF4"].ToString(), reader["UDF5"].ToString(), reader["UDF6"].ToString(), reader["UDF7"].ToString(), reader["UDF8"].ToString(), reader["UDF9"].ToString(), reader["UDF10"].ToString(), reader["REMARK"].ToString(), reader["PACKING_VALIDATION_TEMPLATE"].ToString(), reader["ENABLE_OPP_XDOCK"].ToString(), reader["OPP_ORDER_STRATEGY_ID"].ToString(), reader["ALLOW_OVER_SHIPMENT"].ToString(), reader["APPORTION_RULE"].ToString(), (reader["ORDER_DATE_START_DAYS"].ToString() != "") ? int.Parse(reader["ORDER_DATE_START_DAYS"].ToString()) : 0, (reader["ORDER_DATE_END_DAYS"].ToString() != "") ? int.Parse(reader["ORDER_DATE_END_DAYS"].ToString()) : 0, (reader["MAXIMUM_ORDERS"].ToString() != "") ? int.Parse(reader["MAXIMUM_ORDERS"].ToString()) : 0, (reader["MINIMUM_PERCENT"].ToString() != "") ? decimal.Parse(reader["MINIMUM_PERCENT"].ToString()) : 0M, reader["ORDER_TYPE_RESTRICT01"].ToString(), reader["ORDER_TYPE_RESTRICT02"].ToString(), reader["ORDER_TYPE_RESTRICT03"].ToString(), reader["ORDER_TYPE_RESTRICT04"].ToString(), reader["ORDER_TYPE_RESTRICT05"].ToString(), reader["ORDER_TYPE_RESTRICT06"].ToString(), reader["ENABLE_PACKING_DEFAULT"].ToString(), reader["INSPECT_AT_PACK"].ToString(), reader["MULTI_ZONE_PL_PA"].ToString(), reader["CREATE_PA_TASK_ON_RF_RECEIPT"].ToString(), reader["ORDER_BREAK_DEFAULT"].ToString(), reader["LPN_BARCODE_SYMBOLOGY"].ToString(), reader["LPN_BARCODE_FORMAT"].ToString(), (reader["LPN_LENGTH"].ToString() != "") ? int.Parse(reader["LPN_LENGTH"].ToString()) : 0, reader["LPN_START_NUMBER"].ToString(), reader["NEXT_LPN_NUMBER"].ToString(), reader["LPN_ROLLBACK_NUMBER"].ToString(), reader["CASE_LABEL_TYPE"].ToString(), reader["APPLICATION_ID"].ToString(), (reader["SSCC_1ST_DIGIT"].ToString() != "") ? int.Parse(reader["SSCC_1ST_DIGIT"].ToString()) : 0, reader["UCC_VENDOR_NUMBER"].ToString(), reader["CC_DISCREPANCY_RULE"].ToString(), reader["CC_ADJ_BY_RF"].ToString(), reader["CC_SKU_LOC"].ToString(), reader["PI_SKU_LOC"].ToString(), reader["ALLOW_COMMINGLED_LPN"].ToString(), reader["ALLOW_AUTO_CLOSE_FOR_ASN"].ToString(), reader["ALLOW_AUTO_CLOSE_FOR_PO"].ToString(), reader["ALLOW_SYSTEM_GENERATED_LPN"].ToString(), reader["ALLOW_SINGLE_SCANRECEIVING"].ToString(), reader["BARCODE_CONFIG_ID"].ToString(), reader["TRACK_INVENTORY_BY"].ToString(), reader["DUP_CASE_ID"].ToString(), reader["SKU_SETUP_REQUIRED"].ToString(), reader["IS_ACTIVE"].ToString(), (byte[]) reader["TS"], reader["CREATED_BY"].ToString(), (reader["CREATED_DATE"].ToString() != "") ? DateTime.Parse(reader["CREATED_DATE"].ToString()) : new DateTime(), reader["UPDATED_BY"].ToString(), (reader["UPDATED_DATE"].ToString() != "") ? DateTime.Parse(reader["UPDATED_DATE"].ToString()) : new DateTime(), reader["IS_REQUIRED_EXTERNAL_ID"].ToString(), reader["FINANCE_LOGISTICAL_CTRL"].ToString(), reader["FINANCE_LOGISTICAL_CALC_BY"].ToString(), reader["CHECK_THE_WEIGHT_DIFFERENCE"].ToString(), (reader["PERCENTAGE_WEIGHT_DIFFERENCE"].ToString() != "") ? Convert.ToDecimal(reader["PERCENTAGE_WEIGHT_DIFFERENCE"]) : 0M, reader["DIFFERENCES_IN_APPROACH"].ToString(), reader["SAME_WEIGHT_BY_STYLE"].ToString(), reader["IS_ASNREFER_TO_LOT01"].ToString(), reader["ASN_REFER01"].ToString(), reader["ASN_TO_LOT_ATTR01"].ToString(), reader["IS_ASNREFER_TO_LOT02"].ToString(), reader["ASN_REFER02"].ToString(), reader["ASN_TO_LOT_ATTR02"].ToString(), reader["IS_ASNREFER_TO_LOT03"].ToString(), reader["ASN_REFER03"].ToString(), reader["ASN_TO_LOT_ATTR03"].ToString(), reader["IS_ASNREFER_TO_LOT04"].ToString(), reader["ASN_REFER04"].ToString(), reader["ASN_TO_LOT_ATTR04"].ToString(), reader["IS_ASNREFER_TO_LOT05"].ToString(), reader["ASN_REFER05"].ToString(), reader["ASN_TO_LOT_ATTR05"].ToString());
            }
            if (!reader.IsClosed)
            {
                reader.Close();
            }
            return tradePartnerInfo;
        }

        public DataSet GetTradePartnerByQueryList(List<string> sqlWhere, TradePartnerQueryEntity tradePartnerQuery, string whLoginID)
        {
            string temp = this.SQL_SELECT_ALL_OWNER.Replace("@_@", whLoginID);
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                if (i == 0)
                {
                    temp = temp + " WHERE " + sqlWhere[i].ToString();
                }
                else
                {
                    temp = temp + " AND " + sqlWhere[i].ToString();
                }
            }
            if (!tradePartnerQuery.IsGetAll)
            {
                temp = PagingHelper.GetPagingSQL(temp, tradePartnerQuery.CurrentPage, tradePartnerQuery.PageSize, tradePartnerQuery.SortField, tradePartnerQuery.SortDirection);
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, temp);
        }

        public DataSet GetTradePartnerByQueryList(DataBase dataBase, DbTransaction tran, List<string> sqlWhere, TradePartnerQueryEntity tradePartnerQuery, string whLoginID)
        {
            string temp = this.SQL_SELECT_ALL_OWNER.Replace("@_@", whLoginID);
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                if (i == 0)
                {
                    temp = temp + " WHERE " + sqlWhere[i].ToString();
                }
                else
                {
                    temp = temp + " AND " + sqlWhere[i].ToString();
                }
            }
            if (!tradePartnerQuery.IsGetAll)
            {
                temp = PagingHelper.GetPagingSQL(temp, tradePartnerQuery.CurrentPage, tradePartnerQuery.PageSize, tradePartnerQuery.SortField, tradePartnerQuery.SortDirection);
            }
            return dataBase.ExecuteDataSet(tran, CommandType.Text, temp);
        }

        public int InsertTradePartner(TradePartnerInfo tradePartnerInfo, List<string> whLoginID)
        {
            int result = 0;
            DataBase db = new DataBase();
            DbConnection conn = db.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    tradePartnerInfo.WhID = whLoginID[i].Substring(0, whLoginID[i].Length - 1);
                    SqlParameter[] paras = this.Set_TradePartner_Parameters(tradePartnerInfo);
                    if (paras != null)
                    {
                        result += db.ExecuteNonQuery(tran, CommandType.Text, this.SQL_INSERT_OWNER.Replace("@_@", whLoginID[i]), paras);
                    }
                }
                tran.Commit();
            }
            catch (SqlException sqlEx)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return result;
        }

        public int InsertTradePartner(DataBase dataBase, DbTransaction tran, TradePartnerInfo tradePartnerInfo, List<string> whLoginID)
        {
            int result = 0;
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    tradePartnerInfo.WhID = whLoginID[i].Substring(0, whLoginID[i].Length - 1);
                    SqlParameter[] paras = this.Set_TradePartner_Parameters(tradePartnerInfo);
                    if (paras != null)
                    {
                        result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_INSERT_OWNER.Replace("@_@", whLoginID[i]), paras);
                    }
                }
            }
            catch (SqlException sqlEx)
            {
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }

        private SqlParameter[] Set_TradePartner_Parameters(TradePartnerInfo ownerInfo)
        {
            SqlParameter[] paramArray = new SqlParameter[] { 
                new SqlParameter(this.WH_ID, SqlDbType.VarChar, 30), new SqlParameter(this.OWNER_ID, SqlDbType.VarChar, 20), new SqlParameter(this.TYPE, SqlDbType.VarChar, 30), new SqlParameter(this.COMPANY, SqlDbType.VarChar, 50), new SqlParameter(this.DESCRIPTION, SqlDbType.VarChar, 50), new SqlParameter(this.VAT, SqlDbType.VarChar, 20), new SqlParameter(this.CREDIT_LIMIT, SqlDbType.VarChar, 20), new SqlParameter(this.PO_ALPHA_PREFIX, SqlDbType.VarChar, 10), new SqlParameter(this.ASN_ALPHA_PREFIX, SqlDbType.VarChar, 10), new SqlParameter(this.SO_ALPHA_PREFIX, SqlDbType.VarChar, 10), new SqlParameter(this.CITY, SqlDbType.VarChar, 50), new SqlParameter(this.STATE, SqlDbType.VarChar, 20), new SqlParameter(this.ZIP, SqlDbType.VarChar, 20), new SqlParameter(this.COUNTRY, SqlDbType.VarChar, 30), new SqlParameter(this.COUNTRY_CODE, SqlDbType.VarChar, 20), new SqlParameter(this.ADDRESS, SqlDbType.VarChar, 200), 
                new SqlParameter(this.CONTACT1, SqlDbType.VarChar, 30), new SqlParameter(this.CONTACT2, SqlDbType.VarChar, 30), new SqlParameter(this.PHONE1, SqlDbType.VarChar, 20), new SqlParameter(this.PHONE2, SqlDbType.VarChar, 20), new SqlParameter(this.FAX1, SqlDbType.VarChar, 20), new SqlParameter(this.FAX2, SqlDbType.VarChar, 20), new SqlParameter(this.EMAIL1, SqlDbType.VarChar, 60), new SqlParameter(this.EMAIL2, SqlDbType.VarChar, 60), new SqlParameter(this.B_CITY, SqlDbType.VarChar, 50), new SqlParameter(this.B_STATE, SqlDbType.VarChar, 20), new SqlParameter(this.B_ZIP, SqlDbType.VarChar, 20), new SqlParameter(this.B_COUNTRY, SqlDbType.VarChar, 30), new SqlParameter(this.B_COUNTRY_CODE, SqlDbType.VarChar, 20), new SqlParameter(this.B_ADDRESS, SqlDbType.VarChar, 200), new SqlParameter(this.B_CONTACT1, SqlDbType.VarChar, 30), new SqlParameter(this.B_CONTACT2, SqlDbType.VarChar, 30), 
                new SqlParameter(this.B_PHONE1, SqlDbType.VarChar, 20), new SqlParameter(this.B_PHONE2, SqlDbType.VarChar, 20), new SqlParameter(this.B_FAX1, SqlDbType.VarChar, 20), new SqlParameter(this.B_FAX2, SqlDbType.VarChar, 20), new SqlParameter(this.B_EMAIL1, SqlDbType.VarChar, 60), new SqlParameter(this.B_EMAIL2, SqlDbType.VarChar, 60), new SqlParameter(this.DEFAULT_CARTON_GROUP, SqlDbType.VarChar, 20), new SqlParameter(this.DEFAULT_PACK_ID, SqlDbType.VarChar, 50), new SqlParameter(this.DEFAULT_LOT_TEMPLATE_ID, SqlDbType.VarChar, 20), new SqlParameter(this.DEFAULT_PUTAWAY_RULE_ID, SqlDbType.VarChar, 20), new SqlParameter(this.DEFAULT_PREALLOCATE_RULE_ID, SqlDbType.VarChar, 20), new SqlParameter(this.DEFAULT_ALLOCATE_RULE_ID, SqlDbType.VarChar, 20), new SqlParameter(this.DEFAULT_ROTATION_RULE_ID, SqlDbType.VarChar, 20), new SqlParameter(this.CALCULATE_PUTAWAY_LOCATION, SqlDbType.VarChar, 20), new SqlParameter(this.RECEIPT_VALIDATION_ID, SqlDbType.VarChar, 20), new SqlParameter(this.DEFAULT_QC_LOC, SqlDbType.VarChar, 20), 
                new SqlParameter(this.DEFAULT_QC_LOC_OUT, SqlDbType.VarChar, 20), new SqlParameter(this.DEFAULT_RETURNS_LOC, SqlDbType.VarChar, 20), new SqlParameter(this.DEFAULT_PACKING_LOCATION, SqlDbType.VarChar, 20), new SqlParameter(this.UDF1, SqlDbType.VarChar, 30), new SqlParameter(this.UDF2, SqlDbType.VarChar, 30), new SqlParameter(this.UDF3, SqlDbType.VarChar, 30), new SqlParameter(this.UDF4, SqlDbType.VarChar, 30), new SqlParameter(this.UDF5, SqlDbType.VarChar, 30), new SqlParameter(this.UDF6, SqlDbType.VarChar, 30), new SqlParameter(this.UDF7, SqlDbType.VarChar, 30), new SqlParameter(this.UDF8, SqlDbType.VarChar, 30), new SqlParameter(this.UDF9, SqlDbType.VarChar, 30), new SqlParameter(this.UDF10, SqlDbType.VarChar, 30), new SqlParameter(this.REMARK, SqlDbType.VarChar, 0x7d0), new SqlParameter(this.PACKING_VALIDATION_TEMPLATE, SqlDbType.VarChar, 20), new SqlParameter(this.ENABLE_OPP_XDOCK, SqlDbType.VarChar, 1), 
                new SqlParameter(this.OPP_ORDER_STRATEGY_ID, SqlDbType.VarChar, 20), new SqlParameter(this.ALLOW_OVER_SHIPMENT, SqlDbType.VarChar, 1), new SqlParameter(this.APPORTION_RULE, SqlDbType.VarChar, 20), new SqlParameter(this.ORDER_DATE_START_DAYS, SqlDbType.Int, 4), new SqlParameter(this.ORDER_DATE_END_DAYS, SqlDbType.Int, 4), new SqlParameter(this.MAXIMUM_ORDERS, SqlDbType.Int, 4), new SqlParameter(this.MINIMUM_PERCENT, SqlDbType.Decimal, 9), new SqlParameter(this.ORDER_TYPE_RESTRICT01, SqlDbType.VarChar, 20), new SqlParameter(this.ORDER_TYPE_RESTRICT02, SqlDbType.VarChar, 20), new SqlParameter(this.ORDER_TYPE_RESTRICT03, SqlDbType.VarChar, 20), new SqlParameter(this.ORDER_TYPE_RESTRICT04, SqlDbType.VarChar, 20), new SqlParameter(this.ORDER_TYPE_RESTRICT05, SqlDbType.VarChar, 20), new SqlParameter(this.ORDER_TYPE_RESTRICT06, SqlDbType.VarChar, 20), new SqlParameter(this.ENABLE_PACKING_DEFAULT, SqlDbType.VarChar, 1), new SqlParameter(this.INSPECT_AT_PACK, SqlDbType.VarChar, 1), new SqlParameter(this.MULTI_ZONE_PL_PA, SqlDbType.VarChar, 1), 
                new SqlParameter(this.CREATE_PA_TASK_ON_RF_RECEIPT, SqlDbType.VarChar, 20), new SqlParameter(this.ORDER_BREAK_DEFAULT, SqlDbType.VarChar, 1), new SqlParameter(this.LPN_BARCODE_SYMBOLOGY, SqlDbType.VarChar, 60), new SqlParameter(this.LPN_BARCODE_FORMAT, SqlDbType.VarChar, 60), new SqlParameter(this.LPN_LENGTH, SqlDbType.Int, 4), new SqlParameter(this.LPN_START_NUMBER, SqlDbType.VarChar, 20), new SqlParameter(this.NEXT_LPN_NUMBER, SqlDbType.VarChar, 20), new SqlParameter(this.LPN_ROLLBACK_NUMBER, SqlDbType.VarChar, 20), new SqlParameter(this.CASE_LABEL_TYPE, SqlDbType.VarChar, 20), new SqlParameter(this.APPLICATION_ID, SqlDbType.VarChar, 2), new SqlParameter(this.SSCC_1ST_DIGIT, SqlDbType.Int, 4), new SqlParameter(this.UCC_VENDOR_NUMBER, SqlDbType.VarChar, 9), new SqlParameter(this.CC_DISCREPANCY_RULE, SqlDbType.VarChar, 20), new SqlParameter(this.CC_ADJ_BY_RF, SqlDbType.VarChar, 20), new SqlParameter(this.CC_SKU_LOC, SqlDbType.VarChar, 20), new SqlParameter(this.PI_SKU_LOC, SqlDbType.VarChar, 20), 
                new SqlParameter(this.ALLOW_COMMINGLED_LPN, SqlDbType.VarChar, 1), new SqlParameter(this.ALLOW_AUTO_CLOSE_FOR_ASN, SqlDbType.VarChar, 1), new SqlParameter(this.ALLOW_AUTO_CLOSE_FOR_PO, SqlDbType.VarChar, 1), new SqlParameter(this.ALLOW_SYSTEM_GENERATED_LPN, SqlDbType.VarChar, 1), new SqlParameter(this.ALLOW_SINGLE_SCANRECEIVING, SqlDbType.VarChar, 1), new SqlParameter(this.BARCODE_CONFIG_ID, SqlDbType.VarChar, 20), new SqlParameter(this.TRACK_INVENTORY_BY, SqlDbType.VarChar, 1), new SqlParameter(this.DUP_CASE_ID, SqlDbType.VarChar, 1), new SqlParameter(this.SKU_SETUP_REQUIRED, SqlDbType.VarChar, 1), new SqlParameter(this.IS_ACTIVE, SqlDbType.VarChar, 1), new SqlParameter(this.CREATED_BY, SqlDbType.VarChar, 20), new SqlParameter(this.UPDATED_BY, SqlDbType.VarChar, 20), new SqlParameter(this.IS_REQUIRED_EXTERNAL_ID, SqlDbType.VarChar, 1), new SqlParameter(this.FINANCE_LOGISTICAL_CTRL, SqlDbType.VarChar, 1), new SqlParameter(this.FINANCE_LOGISTICAL_CALC_BY, SqlDbType.VarChar, 20), new SqlParameter(this.CHECK_THE_WEIGHT_DIFFERENCE, SqlDbType.VarChar, 1), 
                new SqlParameter(this.PERCENTAGE_WEIGHT_DIFFERENCE, SqlDbType.Decimal, 0x16), new SqlParameter(this.DIFFERENCES_IN_APPROACH, SqlDbType.VarChar, 20), new SqlParameter(this.SAME_WEIGHT_BY_STYLE, SqlDbType.VarChar, 1), new SqlParameter(this.IS_ASNREFER_TO_LOT01, SqlDbType.VarChar, 1), new SqlParameter(this.ASN_REFER01, SqlDbType.VarChar, 50), new SqlParameter(this.ASN_TO_LOT_ATTR01, SqlDbType.VarChar, 50), new SqlParameter(this.IS_ASNREFER_TO_LOT02, SqlDbType.VarChar, 1), new SqlParameter(this.ASN_REFER02, SqlDbType.VarChar, 50), new SqlParameter(this.ASN_TO_LOT_ATTR02, SqlDbType.VarChar, 50), new SqlParameter(this.IS_ASNREFER_TO_LOT03, SqlDbType.VarChar, 1), new SqlParameter(this.ASN_REFER03, SqlDbType.VarChar, 50), new SqlParameter(this.ASN_TO_LOT_ATTR03, SqlDbType.VarChar, 50), new SqlParameter(this.IS_ASNREFER_TO_LOT04, SqlDbType.VarChar, 1), new SqlParameter(this.ASN_REFER04, SqlDbType.VarChar, 50), new SqlParameter(this.ASN_TO_LOT_ATTR04, SqlDbType.VarChar, 50), new SqlParameter(this.IS_ASNREFER_TO_LOT05, SqlDbType.VarChar, 1), 
                new SqlParameter(this.ASN_REFER05, SqlDbType.VarChar, 50), new SqlParameter(this.ASN_TO_LOT_ATTR05, SqlDbType.VarChar, 50)
             };
            if (!string.IsNullOrEmpty(ownerInfo.WhID))
            {
                paramArray[0].Value = ownerInfo.WhID;
            }
            else
            {
                paramArray[0].Value = DBNull.Value;
            }
            paramArray[1].Value = ownerInfo.OwnerID;
            if (!string.IsNullOrEmpty(ownerInfo.Type))
            {
                paramArray[2].Value = ownerInfo.Type;
            }
            else
            {
                paramArray[2].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.Company))
            {
                paramArray[3].Value = ownerInfo.Company;
            }
            else
            {
                paramArray[3].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.Description))
            {
                paramArray[4].Value = ownerInfo.Description;
            }
            else
            {
                paramArray[4].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.Vat))
            {
                paramArray[5].Value = ownerInfo.Vat;
            }
            else
            {
                paramArray[5].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.CreditLimit))
            {
                paramArray[6].Value = ownerInfo.CreditLimit;
            }
            else
            {
                paramArray[6].Value = DBNull.Value;
            }
            paramArray[7].Value = ownerInfo.PoAlphaPrefix;
            paramArray[8].Value = ownerInfo.AsnAlphaPrefix;
            paramArray[9].Value = ownerInfo.SoAlphaPrefix;
            if (!string.IsNullOrEmpty(ownerInfo.City))
            {
                paramArray[10].Value = ownerInfo.City;
            }
            else
            {
                paramArray[10].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.State))
            {
                paramArray[11].Value = ownerInfo.State;
            }
            else
            {
                paramArray[11].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.Zip))
            {
                paramArray[12].Value = ownerInfo.Zip;
            }
            else
            {
                paramArray[12].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.Country))
            {
                paramArray[13].Value = ownerInfo.Country;
            }
            else
            {
                paramArray[13].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.CountryCode))
            {
                paramArray[14].Value = ownerInfo.CountryCode;
            }
            else
            {
                paramArray[14].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.Address))
            {
                paramArray[15].Value = ownerInfo.Address;
            }
            else
            {
                paramArray[15].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.Contact1))
            {
                paramArray[0x10].Value = ownerInfo.Contact1;
            }
            else
            {
                paramArray[0x10].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.Contact2))
            {
                paramArray[0x11].Value = ownerInfo.Contact2;
            }
            else
            {
                paramArray[0x11].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.Phone1))
            {
                paramArray[0x12].Value = ownerInfo.Phone1;
            }
            else
            {
                paramArray[0x12].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.Phone2))
            {
                paramArray[0x13].Value = ownerInfo.Phone2;
            }
            else
            {
                paramArray[0x13].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.Fax1))
            {
                paramArray[20].Value = ownerInfo.Fax1;
            }
            else
            {
                paramArray[20].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.Fax2))
            {
                paramArray[0x15].Value = ownerInfo.Fax2;
            }
            else
            {
                paramArray[0x15].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.Email1))
            {
                paramArray[0x16].Value = ownerInfo.Email1;
            }
            else
            {
                paramArray[0x16].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.Email2))
            {
                paramArray[0x17].Value = ownerInfo.Email2;
            }
            else
            {
                paramArray[0x17].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.BCity))
            {
                paramArray[0x18].Value = ownerInfo.BCity;
            }
            else
            {
                paramArray[0x18].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.BState))
            {
                paramArray[0x19].Value = ownerInfo.BState;
            }
            else
            {
                paramArray[0x19].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.BZip))
            {
                paramArray[0x1a].Value = ownerInfo.BZip;
            }
            else
            {
                paramArray[0x1a].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.BCountry))
            {
                paramArray[0x1b].Value = ownerInfo.BCountry;
            }
            else
            {
                paramArray[0x1b].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.BCountryCode))
            {
                paramArray[0x1c].Value = ownerInfo.BCountryCode;
            }
            else
            {
                paramArray[0x1c].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.BAddress))
            {
                paramArray[0x1d].Value = ownerInfo.BAddress;
            }
            else
            {
                paramArray[0x1d].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.BContact1))
            {
                paramArray[30].Value = ownerInfo.BContact1;
            }
            else
            {
                paramArray[30].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.BContact2))
            {
                paramArray[0x1f].Value = ownerInfo.BContact2;
            }
            else
            {
                paramArray[0x1f].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.BPhone1))
            {
                paramArray[0x20].Value = ownerInfo.BPhone1;
            }
            else
            {
                paramArray[0x20].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.BPhone2))
            {
                paramArray[0x21].Value = ownerInfo.BPhone2;
            }
            else
            {
                paramArray[0x21].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.BFax1))
            {
                paramArray[0x22].Value = ownerInfo.BFax1;
            }
            else
            {
                paramArray[0x22].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.BFax2))
            {
                paramArray[0x23].Value = ownerInfo.BFax2;
            }
            else
            {
                paramArray[0x23].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.BEmail1))
            {
                paramArray[0x24].Value = ownerInfo.BEmail1;
            }
            else
            {
                paramArray[0x24].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.BEmail2))
            {
                paramArray[0x25].Value = ownerInfo.BEmail2;
            }
            else
            {
                paramArray[0x25].Value = DBNull.Value;
            }
            paramArray[0x26].Value = ownerInfo.DefaultCartonGroup;
            paramArray[0x27].Value = ownerInfo.DefaultPackID;
            if (!string.IsNullOrEmpty(ownerInfo.DefaultLotTemplateID))
            {
                paramArray[40].Value = ownerInfo.DefaultLotTemplateID;
            }
            else
            {
                paramArray[40].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.DefaultPutawayRuleID))
            {
                paramArray[0x29].Value = ownerInfo.DefaultPutawayRuleID;
            }
            else
            {
                paramArray[0x29].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.DefaultPreallocateRuleID))
            {
                paramArray[0x2a].Value = ownerInfo.DefaultPreallocateRuleID;
            }
            else
            {
                paramArray[0x2a].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.DefaultAllocateRuleID))
            {
                paramArray[0x2b].Value = ownerInfo.DefaultAllocateRuleID;
            }
            else
            {
                paramArray[0x2b].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.DefaultRotationRuleID))
            {
                paramArray[0x2c].Value = ownerInfo.DefaultRotationRuleID;
            }
            else
            {
                paramArray[0x2c].Value = DBNull.Value;
            }
            paramArray[0x2d].Value = ownerInfo.CalculatePutawayLocation;
            paramArray[0x2e].Value = ownerInfo.ReceiptValidationID;
            paramArray[0x2f].Value = ownerInfo.DefaultQcLoc;
            paramArray[0x30].Value = ownerInfo.DefaultQcLocOut;
            paramArray[0x31].Value = ownerInfo.DefaultReturnsLoc;
            if (!string.IsNullOrEmpty(ownerInfo.DefaultPackingLocation))
            {
                paramArray[50].Value = ownerInfo.DefaultPackingLocation;
            }
            else
            {
                paramArray[50].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.Udf1))
            {
                paramArray[0x33].Value = ownerInfo.Udf1;
            }
            else
            {
                paramArray[0x33].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.Udf2))
            {
                paramArray[0x34].Value = ownerInfo.Udf2;
            }
            else
            {
                paramArray[0x34].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.Udf3))
            {
                paramArray[0x35].Value = ownerInfo.Udf3;
            }
            else
            {
                paramArray[0x35].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.Udf4))
            {
                paramArray[0x36].Value = ownerInfo.Udf4;
            }
            else
            {
                paramArray[0x36].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.Udf5))
            {
                paramArray[0x37].Value = ownerInfo.Udf5;
            }
            else
            {
                paramArray[0x37].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.Udf6))
            {
                paramArray[0x38].Value = ownerInfo.Udf6;
            }
            else
            {
                paramArray[0x38].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.Udf7))
            {
                paramArray[0x39].Value = ownerInfo.Udf7;
            }
            else
            {
                paramArray[0x39].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.Udf8))
            {
                paramArray[0x3a].Value = ownerInfo.Udf8;
            }
            else
            {
                paramArray[0x3a].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.Udf9))
            {
                paramArray[0x3b].Value = ownerInfo.Udf9;
            }
            else
            {
                paramArray[0x3b].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.Udf10))
            {
                paramArray[60].Value = ownerInfo.Udf10;
            }
            else
            {
                paramArray[60].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.Remark))
            {
                paramArray[0x3d].Value = ownerInfo.Remark;
            }
            else
            {
                paramArray[0x3d].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.PackingValidationTemplate))
            {
                paramArray[0x3e].Value = ownerInfo.PackingValidationTemplate;
            }
            else
            {
                paramArray[0x3e].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.EnableOppXdock))
            {
                paramArray[0x3f].Value = ownerInfo.EnableOppXdock;
            }
            else
            {
                paramArray[0x3f].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.OppOrderStrategyID))
            {
                paramArray[0x40].Value = ownerInfo.OppOrderStrategyID;
            }
            else
            {
                paramArray[0x40].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.AllowOverShipment))
            {
                paramArray[0x41].Value = ownerInfo.AllowOverShipment;
            }
            else
            {
                paramArray[0x41].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.ApportionRule))
            {
                paramArray[0x42].Value = ownerInfo.ApportionRule;
            }
            else
            {
                paramArray[0x42].Value = DBNull.Value;
            }
            paramArray[0x43].Value = ownerInfo.OrderDateStartDays;
            paramArray[0x44].Value = ownerInfo.OrderDateEndDays;
            paramArray[0x45].Value = ownerInfo.MaximumOrders;
            paramArray[70].Value = ownerInfo.MinimumPercent;
            if (!string.IsNullOrEmpty(ownerInfo.OrderTypeRestrict01))
            {
                paramArray[0x47].Value = ownerInfo.OrderTypeRestrict01;
            }
            else
            {
                paramArray[0x47].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.OrderTypeRestrict02))
            {
                paramArray[0x48].Value = ownerInfo.OrderTypeRestrict02;
            }
            else
            {
                paramArray[0x48].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.OrderTypeRestrict03))
            {
                paramArray[0x49].Value = ownerInfo.OrderTypeRestrict03;
            }
            else
            {
                paramArray[0x49].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.OrderTypeRestrict04))
            {
                paramArray[0x4a].Value = ownerInfo.OrderTypeRestrict04;
            }
            else
            {
                paramArray[0x4a].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.OrderTypeRestrict05))
            {
                paramArray[0x4b].Value = ownerInfo.OrderTypeRestrict05;
            }
            else
            {
                paramArray[0x4b].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.OrderTypeRestrict06))
            {
                paramArray[0x4c].Value = ownerInfo.OrderTypeRestrict06;
            }
            else
            {
                paramArray[0x4c].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.EnablePackingDefault))
            {
                paramArray[0x4d].Value = ownerInfo.EnablePackingDefault;
            }
            else
            {
                paramArray[0x4d].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.InspectAtPack))
            {
                paramArray[0x4e].Value = ownerInfo.InspectAtPack;
            }
            else
            {
                paramArray[0x4e].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.MultiZonePlPa))
            {
                paramArray[0x4f].Value = ownerInfo.MultiZonePlPa;
            }
            else
            {
                paramArray[0x4f].Value = DBNull.Value;
            }
            paramArray[80].Value = ownerInfo.CreatePaTaskOnRfReceipt;
            paramArray[0x51].Value = ownerInfo.OrderBreakDefault;
            if (!string.IsNullOrEmpty(ownerInfo.LpnBarcodeSymbology))
            {
                paramArray[0x52].Value = ownerInfo.LpnBarcodeSymbology;
            }
            else
            {
                paramArray[0x52].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.LpnBarcodeFormat))
            {
                paramArray[0x53].Value = ownerInfo.LpnBarcodeFormat;
            }
            else
            {
                paramArray[0x53].Value = DBNull.Value;
            }
            paramArray[0x54].Value = ownerInfo.LpnLength;
            paramArray[0x55].Value = ownerInfo.LpnStartNumber;
            paramArray[0x56].Value = ownerInfo.NextLpnNumber;
            paramArray[0x57].Value = ownerInfo.LpnRollbackNumber;
            paramArray[0x58].Value = ownerInfo.CaseLabelType;
            paramArray[0x59].Value = ownerInfo.ApplicationID;
            paramArray[90].Value = ownerInfo.Sscc1stDigit;
            paramArray[0x5b].Value = ownerInfo.UccVendorNumber;
            paramArray[0x5c].Value = ownerInfo.CcDiscrepancyRule;
            paramArray[0x5d].Value = ownerInfo.CcAdjByRf;
            paramArray[0x5e].Value = ownerInfo.CcSkuLoc;
            paramArray[0x5f].Value = ownerInfo.PiSkuLoc;
            paramArray[0x60].Value = ownerInfo.AllowCommingledLpn;
            paramArray[0x61].Value = ownerInfo.AllowAutoCloseForAsn;
            paramArray[0x62].Value = ownerInfo.AllowAutoCloseForPo;
            paramArray[0x63].Value = ownerInfo.AllowSystemGeneratedLpn;
            paramArray[100].Value = ownerInfo.AllowSingleScanreceiving;
            if (!string.IsNullOrEmpty(ownerInfo.BarcodeConfigID))
            {
                paramArray[0x65].Value = ownerInfo.BarcodeConfigID;
            }
            else
            {
                paramArray[0x65].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.TrackInventoryBy))
            {
                paramArray[0x66].Value = ownerInfo.TrackInventoryBy;
            }
            else
            {
                paramArray[0x66].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.DupCaseID))
            {
                paramArray[0x67].Value = ownerInfo.DupCaseID;
            }
            else
            {
                paramArray[0x67].Value = DBNull.Value;
            }
            paramArray[0x68].Value = ownerInfo.SkuSetupRequired;
            paramArray[0x69].Value = ownerInfo.IsActive;
            paramArray[0x6a].Value = ownerInfo.CreatedBy;
            paramArray[0x6b].Value = ownerInfo.UpdatedBy;
            if (!string.IsNullOrEmpty(ownerInfo.IsRequiredExternalID))
            {
                paramArray[0x6c].Value = ownerInfo.IsRequiredExternalID;
            }
            else
            {
                paramArray[0x6c].Value = DBNull.Value;
            }
            paramArray[0x6d].Value = ownerInfo.Finance_Logistical_Ctrl;
            if (!string.IsNullOrEmpty(ownerInfo.Finance_Logistical_Calc_By))
            {
                paramArray[110].Value = ownerInfo.Finance_Logistical_Calc_By;
            }
            else
            {
                paramArray[110].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.CheckTheWeightDifference))
            {
                paramArray[0x6f].Value = ownerInfo.CheckTheWeightDifference;
            }
            else
            {
                paramArray[0x6f].Value = DBNull.Value;
            }
            paramArray[0x70].Value = ownerInfo.PercentageWeightDifference;
            if (!string.IsNullOrEmpty(ownerInfo.DifferencesInApproach))
            {
                paramArray[0x71].Value = ownerInfo.DifferencesInApproach;
            }
            else
            {
                paramArray[0x71].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.SameWeightByStyle))
            {
                paramArray[0x72].Value = ownerInfo.SameWeightByStyle;
            }
            else
            {
                paramArray[0x72].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.IsAsnreferToLot01))
            {
                paramArray[0x73].Value = ownerInfo.IsAsnreferToLot01;
            }
            else
            {
                paramArray[0x73].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.AsnRefer01))
            {
                paramArray[0x74].Value = ownerInfo.AsnRefer01;
            }
            else
            {
                paramArray[0x74].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.AsnToLotAttr01))
            {
                paramArray[0x75].Value = ownerInfo.AsnToLotAttr01;
            }
            else
            {
                paramArray[0x75].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.IsAsnreferToLot02))
            {
                paramArray[0x76].Value = ownerInfo.IsAsnreferToLot02;
            }
            else
            {
                paramArray[0x76].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.AsnRefer02))
            {
                paramArray[0x77].Value = ownerInfo.AsnRefer02;
            }
            else
            {
                paramArray[0x77].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.AsnToLotAttr02))
            {
                paramArray[120].Value = ownerInfo.AsnToLotAttr02;
            }
            else
            {
                paramArray[120].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.IsAsnreferToLot03))
            {
                paramArray[0x79].Value = ownerInfo.IsAsnreferToLot03;
            }
            else
            {
                paramArray[0x79].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.AsnRefer03))
            {
                paramArray[0x7a].Value = ownerInfo.AsnRefer03;
            }
            else
            {
                paramArray[0x7a].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.AsnToLotAttr03))
            {
                paramArray[0x7b].Value = ownerInfo.AsnToLotAttr03;
            }
            else
            {
                paramArray[0x7b].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.IsAsnreferToLot04))
            {
                paramArray[0x7c].Value = ownerInfo.IsAsnreferToLot04;
            }
            else
            {
                paramArray[0x7c].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.AsnRefer04))
            {
                paramArray[0x7d].Value = ownerInfo.AsnRefer04;
            }
            else
            {
                paramArray[0x7d].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.AsnToLotAttr04))
            {
                paramArray[0x7e].Value = ownerInfo.AsnToLotAttr04;
            }
            else
            {
                paramArray[0x7e].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.IsAsnreferToLot05))
            {
                paramArray[0x7f].Value = ownerInfo.IsAsnreferToLot05;
            }
            else
            {
                paramArray[0x7f].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.AsnRefer05))
            {
                paramArray[0x80].Value = ownerInfo.AsnRefer05;
            }
            else
            {
                paramArray[0x80].Value = DBNull.Value;
            }
            if (!string.IsNullOrEmpty(ownerInfo.AsnToLotAttr05))
            {
                paramArray[0x81].Value = ownerInfo.AsnToLotAttr05;
                return paramArray;
            }
            paramArray[0x81].Value = DBNull.Value;
            return paramArray;
        }

        public int UpdateTradePartner(TradePartnerInfo tradePartnerInfo, List<string> whLoginID)
        {
            int result = 0;
            DataBase db = new DataBase();
            DbConnection conn = db.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    tradePartnerInfo.WhID = whLoginID[i].Substring(0, whLoginID[i].Length - 1);
                    SqlParameter[] paras = this.Set_TradePartner_Parameters(tradePartnerInfo);
                    if (paras != null)
                    {
                        result += db.ExecuteNonQuery(tran, CommandType.Text, this.SQL_UPDATE_OWNER.Replace("@_@", whLoginID[i]), paras);
                    }
                }
                tran.Commit();
            }
            catch (SqlException sqlEx)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return result;
        }

        public int UpdateTradePartner(DataBase dataBase, DbTransaction tran, TradePartnerInfo tradePartnerInfo, List<string> whLoginID)
        {
            int result = 0;
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    tradePartnerInfo.WhID = whLoginID[i].Substring(0, whLoginID[i].Length - 1);
                    SqlParameter[] paras = this.Set_TradePartner_Parameters(tradePartnerInfo);
                    if (paras != null)
                    {
                        result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_UPDATE_OWNER.Replace("@_@", whLoginID[i]), paras);
                    }
                }
            }
            catch (SqlException sqlEx)
            {
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }
    }
}

